package com.bw.paper.mvp.base.presenter;

import com.bw.paper.mvp.base.model.BaseEntity;
import com.bw.paper.mvp.base.model.IModel;
import com.bw.paper.mvp.base.view.IView;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public abstract class BasePresenter<M extends IModel,V extends IView> implements IPresenter, Observer<BaseEntity> {
    private CompositeDisposable compositeDisposable;

   protected  M mModel;
   protected  V mView;

    public BasePresenter(M mModel, V mView) {
        this.mModel = mModel;
        this.mView = mView;
         compositeDisposable = new CompositeDisposable();
    }




    @Override
    public void onSubscribe(@NonNull Disposable d) {
        compositeDisposable.add(d);
        mView.showDialog();

    }


    @Override
    public void onError(@NonNull Throwable e) {
        mView.showMsg(e.getMessage());

    }

    @Override
    public void onComplete() {
        mView.hideDialog();

    }

    @Override
    public void onDestrory() {
        compositeDisposable.dispose();
        compositeDisposable.clear();
    }
}
